﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using SuperMarketManagement.Entity;

namespace SuperMarketManagement.DAO.NHibernate
{
    public class CustomerDAO : GenericDAO<Customer, long>
    {
        public CustomerDAO(ISession session)
            : base(session)
        {
        }

        public IList<Customer> FindByKeyword(string keyword)
        {
            string likePhrase = "%" + keyword + "%";
            return Session.CreateCriteria(typeof (Customer))
                .Add(
                Expression.Or(
                    Expression.InsensitiveLike("Name", likePhrase),
                    Expression.InsensitiveLike("Cellphone", likePhrase)
                    )
                ).List<Customer>();
        }
    }
}
